package org.smart4j.bootstrap.action;

import org.smart4j.framework.mvc.DataContext;
import org.smart4j.framework.mvc.annotation.Action;
import org.smart4j.framework.mvc.annotation.Request;
import org.smart4j.framework.mvc.bean.Params;
import org.smart4j.framework.mvc.bean.Result;
import org.smart4j.framework.mvc.bean.View;
import org.smart4j.framework.util.CastUtil;
import org.smart4j.plugin.security.SecurityHelper;
import org.smart4j.plugin.security.fault.LoginException;

@Action
public class SystemAction {

    @Request.Get("/login")
    public View login() {
        return new View("login.jsp");
    }

    @Request.Post("/login")
    public Result loginSubmit(Params params) {
        String username = params.getString("username");
        String password = params.getString("password");
        String rememberMe =params.getString("rememberMe");
        boolean isRememberMe;
        if (rememberMe.equals("on"))
            isRememberMe=true;
        else
            isRememberMe=false;
        try {
            SecurityHelper.login(username, password, isRememberMe);
        } catch (LoginException e) {
            return new Result(false);
        }

        return new Result(true);
    }

    @Request.Get("/signup")
    public View signup() {
        return new View("signup.jsp");
    }

    @Request.Post("/signup")
    public View signupSubmit(Params params) {
        return new View("/welcome");
    }

    @Request.Get("/welcome")
    public View welcome() {
        return new View("index.jsp");
    }

    @Request.Get("/logout")
    public Result logout() {
        SecurityHelper.logout();
        DataContext.Session.removeAll();
        return new Result(true);
    }
    @Request.Get("/test")
    public  View test(){
        return  new View("test.jsp");
    }

    @Request.Get("/index")
    public  View index(){
        return  new View("index.jsp");
    }

    @Request.Get("/elements")
    public  View elements(){
        return  new View("elements.jsp");
    }

    @Request.Get("/error")
    public  View error(){
        return  new View("error.jsp").data("test","测试内容");
    }

    @Request.Get("/bonus")
    public  View bonus(){
        return  new View("bonus.jsp");
    }

    @Request.Get("/faq")
    public  View faq(){
        return  new View("faq.jsp");
    }

    @Request.Get("/gallery")
    public  View gallery(){
        return  new View("gallery.jsp");
    }

    @Request.Get("/jqueryui")
    public  View jqueryui(){
        return  new View("jqueryui.jsp");
    }

    @Request.Get("/pricing")
    public  View pricing(){
        return  new View("pricing.jsp");
    }


    @Request.Get("/reports")
    public  View reports(){
        return  new View("reports.jsp");
    }

    @Request.Get("/settings")
    public  View settings(){
        return  new View("settings.jsp");
    }

    @Request.Get("/skins")
    public  View skins(){
        return  new View("skins.jsp");
    }

    @Request.Get("/charts")
    public  View charts(){
        return  new View("charts.jsp");
    }

    @Request.Get("/sticky")
    public  View sticky(){
        return  new View("sticky.jsp");
    }

    @Request.Get("/validation")
    public  View validation(){
        return  new View("validation.jsp");
    }



}
